package net.jlibrary.group.action;

import javax.annotation.Resource;

import org.springframework.ui.ModelMap;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import net.jlibrary.common.core.annotation.Token;
import net.jlibrary.common.core.entity.Pagination;
import net.jlibrary.common.core.entity.PaginationParam;
import net.jlibrary.group.action.vo.ParkingPlaceAdminActionVo;
import net.jlibrary.group.service.IParkingPlaceManager;

@RestController
@RequestMapping("/group")
public class ParkingPlaceAdminAction {
	@Resource
	private IParkingPlaceManager parkingPlaceManager;
	
	@RequestMapping(value = "/parkingPlaceAdminView", method = {RequestMethod.GET})
	public ModelAndView view() {
		return new ModelAndView("/group/parkingPlaceAdminView");
	}
	@RequestMapping(value = "/parkingPlaceAdminJsonList", method = {RequestMethod.POST})
	public Pagination lists(ParkingPlaceAdminActionVo parkingPlace ,PaginationParam param) {
		Pagination pagination = parkingPlaceManager.listsPage(parkingPlace, param);
		return pagination;
	}
	@RequestMapping(value = "/parkingPlaceAdminJsonDetail", method = {RequestMethod.GET})
	public ParkingPlaceAdminActionVo detail(ParkingPlaceAdminActionVo parkingPlace) {
		parkingPlace =  parkingPlaceManager.get(parkingPlace);
		return parkingPlace;
	}
	@RequestMapping(value = "/parkingPlaceAdminJsonAddFormInit", method = {RequestMethod.GET})
	public ParkingPlaceAdminActionVo addFormInit() {
		ParkingPlaceAdminActionVo parkingPlace = new ParkingPlaceAdminActionVo();
		return parkingPlace;
	}
	@RequestMapping(value = "/parkingPlaceAdminJsonSave", method = {RequestMethod.POST})
	@Token
	public ModelMap save(@ModelAttribute("vm") ParkingPlaceAdminActionVo parkingPlace, @Token String token, BindingResult result) {
		parkingPlaceManager.save(parkingPlace);
		ModelMap map = new ModelMap();
		map.put("success", true);
		return map;
	}
	
	@RequestMapping(value = "/parkingPlaceAdminJsonUpdate", method = {RequestMethod.POST})
	@Token
	public ModelMap update(@ModelAttribute("vm") ParkingPlaceAdminActionVo parkingPlace, @Token String token, BindingResult result) {
		parkingPlaceManager.update(parkingPlace);
		ModelMap map = new ModelMap();
		map.put("success", true);
		return map;
	}
	
	@RequestMapping(value = "/parkingPlaceAdminJsonDelete", method = {RequestMethod.POST})
	public ModelMap delete(Long id) {
		ParkingPlaceAdminActionVo parkingPlace = new ParkingPlaceAdminActionVo();
		parkingPlace.setId(id);
		parkingPlaceManager.delete(parkingPlace);
		ModelMap map = new ModelMap();
		map.put("success", true);
		return map;
	}
	
	@RequestMapping(value = "/parkingPlaceAdminJsonRenew", method = {RequestMethod.POST})
	public ModelMap renew(Long id) {
		ParkingPlaceAdminActionVo parkingPlace = new ParkingPlaceAdminActionVo();
		parkingPlace.setId(id);
		parkingPlaceManager.renew(parkingPlace);
		ModelMap map = new ModelMap();
		map.put("success", true);
		return map;
	}
	
}
